--#include "data\functions\Boss\ArenaBoss.lua" once   --擂台BOSS
--#include "data\functions\Exep\ExepArenaBoss.lua" once   	--擂台BOSS（体验）

local npcId = 163
NpcDialog[npcId] = {}
NpcDialog[179] = {}
NpcDialog[180] = {}
NpcDialog[181] = {}
NpcDialog[182] = {}
NpcDialog[183] = {}
NpcDialog[184] = {}
NpcDialog[185] = {}
NpcDialog[186] = {}
NpcDialog[187] = {}
NpcDialog[188] = {}
NpcDialog[189] = {}
NpcDialog[190] = {}

--体验的
NpcDialog[192] = {}				
NpcDialog[193] = {}


local t   = NpcDialog[npcId]
local t1  = NpcDialog[179]
local t2  = NpcDialog[180]
local t3  = NpcDialog[181]
local t4  = NpcDialog[182]
local t5  = NpcDialog[183]
local t6  = NpcDialog[184]
local t7  = NpcDialog[185]
local t8  = NpcDialog[186]
local t9  = NpcDialog[187]
local t10 = NpcDialog[188]
local t11 = NpcDialog[189]
local t12 = NpcDialog[190]

--体验的擂台BOSS
local exepT1 = NpcDialog[192]
local exepT2 = NpcDialog[193]

t.main = function(sysarg)
	local circleLimit 	= ArenaBossConfig.enterLevelLimit[1]
	local levelLimit 	= ArenaBossConfig.enterLevelLimit[2]
	local vipGrade   	= Actor.getVipGrade( sysarg )

	local maxTimes   	= GetActorDailyMaxTimes( sysarg, enDailyOpTimes_ArenaBoss, 0 )
	local doneTimes  	= GetActorDailyDoneTimes( sysarg, enDailyOpTimes_ArenaBoss, 0 )
	local lastTimes  	= maxTimes - doneTimes
	if lastTimes < 0 then
		lastTimes = 0
	end

	local strColor1 = Lang.ScriptTips.Color_Greed
	if not Actor.checkActorLevel( sysarg, levelLimit, circleLimit ) then
		strColor1 = Lang.ScriptTips.Color_Red
	end

	local openDays = System.getDaysSinceOpenServer()
	local needVip = 0
	if openDays <= ArenaBossConfig.enterVipLimit[1] then
		needVip = ArenaBossConfig.enterVipLimit[2] 		--开服N天内需要VIP等级
	else
		needVip = ArenaBossConfig.enterVipLimit[3] 		--开服N天后需要VIP等级
	end

	local strColor2 = Lang.ScriptTips.Color_Greed
	if vipGrade < needVip then
		strColor2 = Lang.ScriptTips.Color_Red
	end

	--[[
	local strColor3 = Lang.ScriptTips.Color_Greed
	if lastTimes <= 0 then
		strColor3 = Lang.ScriptTips.Color_Red
	end
	]]
	local strCond1 = string.format( Lang.ScriptTips.LevelLimitCircleFormat, strColor1, circleLimit, levelLimit )
	local strCond2 = ""
	if needVip > 0 then
		strCond2 = string.format( Lang.ScriptTips.VipLimitFormat, strColor2, needVip )
	end
	--local strCond3 = string.format( Lang.ScriptTips.LastTimesFormat, strColor3, lastTimes )

	local strCond = ""
	if strCond2 ~= "" then
		strCond  = strCond1.."\n"..strCond2
	else
		strCond  = strCond1
	end

	-----------------
	local strDesc = Lang.ScriptTips.ArenaBossDesc01
	------------------
	local okBtn 	 = "{btn;0;"..Lang.ScriptTips.ButtonEnter..";%s;}"			--{按钮;样式;按钮名;函数名;描述}
	local strBtnList = string.format(okBtn, "EnterAreanBoss")

	local pack = DataPack.allocPacket(sysarg, LogicCmd.npcDialogSys.sysID, LogicCmd.npcDialogSys.sub.sNpcDlgData)
	DataPack.writeUint64(pack, Actor.getNpc(sysarg))
	DataPack.writeByte(pack, NpcDialogType.GeneralNpcDlg)
	DataPack.writeString(pack, strCond)
	DataPack.writeString(pack, strDesc)
	DataPack.writeString(pack, strBtnList)
	DataPack.writeChar(pack, -1)
	DataPack.writeByte(pack, 0);
	DataPack.flush(pack)

	--local playerHandle = Actor.getNpc(sysarg)
	--print("npc 163, playerHandle="..playerHandle)
end

t1.main = function(sysarg)
	NpcCallBoss( sysarg, 1 )
end

t2.main = function(sysarg)
	NpcCallBoss( sysarg, 2 )
end

t3.main = function(sysarg)
	NpcCallBoss( sysarg, 3 )
end

t4.main = function(sysarg)
	NpcCallBoss( sysarg, 4 )
end

t5.main = function(sysarg)
	NpcCallBoss( sysarg, 5 )
end

t6.main = function(sysarg)
	NpcCallBoss( sysarg, 6 )
end

t7.main = function(sysarg)
	NpcCallBoss( sysarg, 7 )
end

t8.main = function(sysarg)
	NpcCallBoss( sysarg, 8 )
end

t9.main = function(sysarg)
	NpcCallBoss( sysarg, 9 )
end

t10.main = function(sysarg)
	NpcCallBoss( sysarg, 10 )
end

t11.main = function(sysarg)
	NpcCallBoss( sysarg, 11 )
end

t12.main = function(sysarg)
	NpcCallBoss( sysarg, 12 )
end

exepT1.main = function(sysarg)
	NpcCallExepArenaBoss( sysarg, 1 )
end

exepT2.main = function(sysarg)
	NpcCallExepArenaBoss( sysarg, 2 )
end

function NpcCallBoss( sysarg, bossIdx )
	local bossCfg = ArenaBossConfig.boss[bossIdx]
	if not bossCfg then
		return
	end
	CallArenaBoss( sysarg, bossCfg )
end

function NpcCallExepArenaBoss( sysarg, bossIdx )
	--print("NpcCallExepArenaBoss, bossIdx="..bossIdx)
	local bossCfg = ExepArenaBossConfig.boss[bossIdx]
	if not bossCfg then
		return
	end
	CallExepArenaBoss( sysarg, bossCfg )
end

function CallArenaBoss( sysarg, bossCfg )
	local needYuanBao 	= bossCfg.callBossWithYuanBao.count
	local needItemId 	= bossCfg.callBossWithItem.id
	local needItemCount	= bossCfg.callBossWithItem.count
	local itemName 		= Item.getItemName( needItemId )

	local strColor1 = Lang.ScriptTips.Color_Greed
	if Actor.getMoneyCount(sysarg, mtYuanbao) < needYuanBao then
		strColor1 = Lang.ScriptTips.Color_Red
	end

	local strColor2 = Lang.ScriptTips.Color_Greed
	if Actor.getItemCount(sysarg, needItemId) < needItemCount then
		strColor2 = Lang.ScriptTips.Color_Red
	end

	local strColor3 = Lang.ScriptTips.Color_Greed

	local strColor4 = Lang.ScriptTips.Color_Greed
	if not Actor.checkActorLevel( sysarg, bossCfg.recomLevel[2], bossCfg.recomLevel[1] ) then
		strColor4 = Lang.ScriptTips.Color_Red
	end

	local strCond1  = string.format(Lang.ScriptTips.YuanBaoCallFormat, strColor1, needYuanBao )
	local strCond2  = string.format(Lang.ScriptTips.ItemCallFormat, strColor2, itemName, needItemCount )
	local strCond3  = string.format(Lang.ScriptTips.BossLevelFormat, strColor3, bossCfg.bossLevel )
	local strCond4  = string.format(Lang.ScriptTips.RecomLevelFormat, strColor4, bossCfg.recomLevel[1],  bossCfg.recomLevel[2])

	local strCond   = strCond1.."\n"..strCond2.."\n"..strCond3.."\n"..strCond4
	------------------
	local strDesc = Lang.ScriptTips.ArenaBossDesc04

	local okBtn1 	 = "{btn;0;"..Lang.ScriptTips.ButtonYBCall..";%s;}"			--{按钮;样式;按钮名;函数名;描述}
	local okBtn2 	 = "{btn;0;"..Lang.ScriptTips.ButtonItemCall..";%s;}"			--{按钮;样式;按钮名;函数名;描述}

	local strBtnList = string.format( okBtn1, string.format("CallAreanBoss,%d,%d", bossCfg.bossIdx, 1) )
	strBtnList = strBtnList .. string.format( okBtn2 , string.format("CallAreanBoss,%d,%d", bossCfg.bossIdx, 2) )

	local pack = DataPack.allocPacket(sysarg, LogicCmd.npcDialogSys.sysID, LogicCmd.npcDialogSys.sub.sNpcDlgData)
	DataPack.writeUint64(pack, Actor.getNpc(sysarg))
	DataPack.writeByte(pack, NpcDialogType.ArenaBossDlg)					--擂台BOSS面板 
	DataPack.writeString(pack, strCond)
	DataPack.writeString(pack, strDesc)
	DataPack.writeString(pack, strBtnList)
	DataPack.writeChar(pack, -1)
	DataPack.writeByte(pack, 0);
	DataPack.flush(pack)
end


function CallExepArenaBoss( sysarg, bossCfg )
	--print("CallExepArenaBoss...")
	--local needYuanBao 	= bossCfg.callBossWithYuanBao.count
	local needItemId 	= bossCfg.callBossWithItem.id
	local needItemCount	= bossCfg.callBossWithItem.count
	local itemName 		= Item.getItemName( needItemId )

	--[[
	local strColor1 = Lang.ScriptTips.Color_Greed
	if Actor.getMoneyCount(sysarg, mtYuanbao) < needYuanBao then
		strColor1 = Lang.ScriptTips.Color_Red
	end
	]]

	local strColor2 = Lang.ScriptTips.Color_Greed
	if Actor.getItemCount(sysarg, needItemId) < needItemCount then
		strColor2 = Lang.ScriptTips.Color_Red
	end

	--local strCond1  = string.format(Lang.ScriptTips.YuanBaoCallFormat, strColor1, needYuanBao )
	local strCond2  = string.format(Lang.ScriptTips.ItemCallFormat, strColor2, itemName, needItemCount )
	--local strCond   = strCond1.."\n"..strCond2
	local strCond   = strCond2
	------------------
	local strDesc = Lang.ScriptTips.ArenaBossDesc04

	--local okBtn1 	 = "{btn;0;"..Lang.ScriptTips.ButtonYBCall..";%s;}"			--{按钮;样式;按钮名;函数名;描述}
	local okBtn2 	 = "{btn;0;"..Lang.ScriptTips.ButtonItemCall..";%s;}"			--{按钮;样式;按钮名;函数名;描述}

	--local strBtnList = string.format( okBtn1, string.format("CallAreanBoss,%d,%d", bossIdx, 1) )
	local strBtnList = string.format( okBtn2 , string.format("CallAreanBoss,%d,%d", bossCfg.bossIdx, 2) )

	local pack = DataPack.allocPacket(sysarg, LogicCmd.npcDialogSys.sysID, LogicCmd.npcDialogSys.sub.sNpcDlgData)
	DataPack.writeUint64(pack, Actor.getNpc(sysarg))
	DataPack.writeByte(pack, NpcDialogType.ExepArenaBossDlg)					--擂台BOSS面板（体验） 
	DataPack.writeString(pack, strCond)
	DataPack.writeString(pack, strDesc)
	DataPack.writeString(pack, strBtnList)
	DataPack.writeChar(pack, -1)
	DataPack.writeByte(pack, 0);
	DataPack.flush(pack)
end


t.EnterAreanBoss = function(sysarg)
	EnterArenaBoss( sysarg )
	--EnterExepArenaBoss( sysarg )			--进入体验BOSS副本（测试用）
end


t1.CallAreanBoss = function(sysarg, bossIdx, callType)
	bossIdx = tonumber(bossIdx)
	callType = tonumber(callType)
	challengeArenaBoss( sysarg, bossIdx, callType)
end

t2.CallAreanBoss = function(sysarg, bossIdx, callType)
	bossIdx = tonumber(bossIdx)
	callType = tonumber(callType)
	challengeArenaBoss( sysarg, bossIdx, callType)
end

t3.CallAreanBoss = function(sysarg, bossIdx, callType)
	bossIdx = tonumber(bossIdx)
	callType = tonumber(callType)
	challengeArenaBoss( sysarg, bossIdx, callType)
end

t4.CallAreanBoss = function(sysarg, bossIdx, callType)
	bossIdx = tonumber(bossIdx)
	callType = tonumber(callType)
	challengeArenaBoss( sysarg, bossIdx, callType)
end

t5.CallAreanBoss = function(sysarg, bossIdx, callType)
	bossIdx = tonumber(bossIdx)
	callType = tonumber(callType)
	challengeArenaBoss( sysarg, bossIdx, callType)
end

t6.CallAreanBoss = function(sysarg, bossIdx, callType)
	bossIdx = tonumber(bossIdx)
	callType = tonumber(callType)
	challengeArenaBoss( sysarg, bossIdx, callType)
end

t7.CallAreanBoss = function(sysarg, bossIdx, callType)
	bossIdx = tonumber(bossIdx)
	callType = tonumber(callType)
	challengeArenaBoss( sysarg, bossIdx, callType)
end

t8.CallAreanBoss = function(sysarg, bossIdx, callType)
	bossIdx = tonumber(bossIdx)
	callType = tonumber(callType)
	challengeArenaBoss( sysarg, bossIdx, callType)
end

t9.CallAreanBoss = function(sysarg, bossIdx, callType)
	bossIdx = tonumber(bossIdx)
	callType = tonumber(callType)
	challengeArenaBoss( sysarg, bossIdx, callType)
end

t10.CallAreanBoss = function(sysarg, bossIdx, callType)
	bossIdx = tonumber(bossIdx)
	callType = tonumber(callType)
	challengeArenaBoss( sysarg, bossIdx, callType)
end

t11.CallAreanBoss = function(sysarg, bossIdx, callType)
	bossIdx = tonumber(bossIdx)
	callType = tonumber(callType)
	challengeArenaBoss( sysarg, bossIdx, callType)
end

t12.CallAreanBoss = function(sysarg, bossIdx, callType)
	bossIdx = tonumber(bossIdx)
	callType = tonumber(callType)
	challengeArenaBoss( sysarg, bossIdx, callType)
end

exepT1.CallAreanBoss = function(sysarg, bossIdx, callType)
	bossIdx = tonumber(bossIdx)
	callType = tonumber(callType)
	challengeExepArenaBoss( sysarg, bossIdx, callType)
end

exepT2.CallAreanBoss = function(sysarg, bossIdx, callType)
	bossIdx = tonumber(bossIdx)
	callType = tonumber(callType)
	challengeExepArenaBoss( sysarg, bossIdx, callType)
end

